/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.isi.pegasus.planner.subworkflow.scheduler;

import edu.isi.pegasus.common.util.DynamicLoader;
import edu.isi.pegasus.planner.classes.ADag;
import edu.isi.pegasus.planner.classes.PegasusBag;
import java.util.HashMap;
import java.util.Map;

/**
 *
 * @author wchen
 */
 public class SchedulerFactory {

    public static final String DEFAULT_SCHEDULER = "Static";
    private static final String DEFAULT_PACKAGE_NAME =
            "edu.isi.pegasus.planner.subworkflow.scheduler.implementation";
    

    public static SchedulerImplementation loadInstance( ADag mDag, PegasusBag mBag, String className)
    {
        SchedulerImplementation scheduler = null;
        Map schedulerMap  = new HashMap<String, String>();
        schedulerMap.put("static", "Static");
        schedulerMap.put("minmin", "MinMin");
        schedulerMap.put("heft", "HEFT");
        schedulerMap.put("reorder", "Reorder");
        schedulerMap.put("pure","PureScheduler");
        if(className == null || className.equals(""))
            className = DEFAULT_SCHEDULER;
        className = (String)schedulerMap.get(className.toLowerCase()); 
        className = (className.indexOf('.') == -1) ? DEFAULT_PACKAGE_NAME + "." + className : className;
        DynamicLoader dl = new DynamicLoader(className);
        Object argList[] = new Object[2];
        argList[0] = mDag;
        argList[1] = mBag;
        try
        {
            scheduler = (SchedulerImplementation) dl.instantiate(argList);

        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
        return scheduler;

    }
}
